'use strict'

const titbit = require('titbit');
const app = new titbit({
  debug: true
})


app.use(async (c, next) => {
  if (!c.query.passkey || c.query.passkey !== '123456') {
    c.res.body = 'permission deny';
    return;
  }

  console.log(c.path, 'start');
  await next();
  console.log(c.path, 'end');
})

app.get('/', async c => {
  c.res.body = 'success';
})

app.get('/test', async c => {
  c.res.body = Date.now();
})

app.use(async (c, next) => {
  console.log('set max body');
  //设置最大允许提交的10字节
  c.maxBody = 10;
  await next();

  //设置pre为true等效于使用pre，
  //提供method指定针对哪写请求方法执行
}, { pre: true, method: 'POST' })

app.post('/test', async c => {
  //返回提交的数据
  c.res.body = c.body;
})

app.run(8934);
